<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display();
    }
    public function verify(){
    	foreach ($_POST as $key => $value) {
    		if (empty($value)) {
    			$this->error("请输入完整的信息","",2);
    		}
    	}
    	$code=$_POST['verify'];
    	$verify = new \Think\Verify();
   		$check=$verify->check($code);
   		if ($check==true) {
   			$db=M('login');
   			$exist=$db->where("name='{$_POST['name']}'","password='{$_POST['password']}'")->find();
   			if (!empty($exist)) {
   				$_SESSION['name']=$exist['name'];
   				$_SESSION['id']=$exist['id'];  				
   				$this->success('登录成功','/Admin/Index/index',2);
   			}else{
   				$this->error('用户名或密码错误','',2);
   			}
   		}else{
        $this->error('验证码错误','',2);
      }
    }
    public function out(){
    	$_SESSION['name']=null;
    	$_SESSION['id']=null;
    	$this->redirect("/Admin/Login/index");

    }
}